/*
 * @lc app=leetcode.cn id=1122 lang=cpp
 *
 * [1122] 数组的相对排序
 */

// @lc code=start
class Solution {
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
        int tmp[1001] = {0};
        for(auto i : arr1)
            tmp[i]++;
        
        vector<int> res;

        for(auto i : arr2)
            while(tmp[i])
                res.push_back(i), tmp[i]--;

        for(int i = 0; i < 1001; i++)
        {
            while(tmp[i])
                res.push_back(i), tmp[i]--;
        }

        return res;
    }
};
// @lc code=end

